package mathive.client.menu;

import org.adamtacy.client.ui.NEffectPanel;
import org.adamtacy.client.ui.effects.impl.Fade;
import org.adamtacy.client.ui.effects.impl.Move;
import org.adamtacy.client.ui.effects.transitionsphysics.EaseOutTransitionPhysics;

import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class MenuButton extends Image {
	private Image text;
	private NEffectPanel effect;
	
	public MenuButton(String buttonPath, String text) {
		super(buttonPath);
		Label text2 = new Label(text);
		text2.addStyleName("menutext");
		addStyleName("cursor");
		Move move = new Move(0, -50);
		move.setDuration(0.2);
		Fade fade = new Fade();
		
		fade.setStartOpacity(0);
		fade.setEndOpacity(100);
		fade.setDuration(0.2);
		effect = new NEffectPanel();
		effect.setEffectsTransitionType(new EaseOutTransitionPhysics());
		effect.add(text2);
		effect.addEffect(move);
		effect.addEffect(fade);
		
		Window.addResizeHandler(new WindowResizeHandler());
		update();
	}
	
	public Widget getText() {
		return effect;
	}
	
	public void textUp() {
		effect.resumeEffectsForwards();
	}
	
	public void textDown() {
		effect.resumeEffectsBackwards();
	}
	
	private void update() {
		setSize("auto", "" + Window.getClientHeight() * 0.1);
	}
	
	private class WindowResizeHandler implements ResizeHandler {
		@Override
		public void onResize(ResizeEvent event) {
			update();
		}
	}
}
